package net.cloudsun.graph.puzzle.group;

import net.cloudsun.graph.puzzle.JigsawState;
import net.cloudsun.graph.puzzle.PuzzlePosition;

/**
 * 创建群
 * created at 23/11/2021
 *
 * @author 俞建波
 * <a href="mailto://yujianbo@chtwm.com">yujianbo@chtwm.com</a>
 * @since 1.1.0
 */
public class PuzzleSmallRotateGroupBuilder extends AbstractPuzzleGroupBuilder<PuzzleSmallRotateGroup> {

    private PuzzlePosition position;

    public PuzzleSmallRotateGroupBuilder(PuzzlePosition position) {
        this.position = position;
    }


    @Override
    protected boolean check(String line) {
        // 0 1 2 3 4 5 6 7 8
        final char c = line.charAt(4);
        final int startColumn = this.position.getStartColumn();
        final int startRow = this.position.getStartRow();
        int endColumn = startColumn + 1;
        int endRow = startRow + 1;
        final int i = line.indexOf('8');
        final int row = i / 3;
        final int column = i % 3;
        return row >= startRow && row <= endRow && column >= startColumn && column <= endColumn;
    }

    @Override
    protected PuzzleSmallRotateGroup newGroup(JigsawState element) {
        return new PuzzleSmallRotateGroup(element, position);
    }
}
